package main

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"time"
)

type User struct {
	gorm.Model
	Name string
	Age *int
	BirthDay time.Time
	Sex int
	Email *string
}

func main() {
	dsn := "root:123@tcp(127.0.0.1:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	db.AutoMigrate(&User{})
	email := "123@qq.com"
	//age := 22
	user := User{
		Name:     "Alex1",
		BirthDay: time.Now(),
		//Age: &age,
		Email: &email,
	}
	//result := db.Debug().Select("name").Create(&user)
	db.Debug().Create(&user)
	fmt.Println(user)


/*	var users = []User{{Name: "jinzhu1"}, {Name: "jinzhu2"}, {Name: "jinzhu3"}}
	db.Debug().Create(&users)*/


}